<template>
  <div class="home">
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="activePath"
          class="el-menu-vertical-demo"
          router
          @open="handleOpen"
          @close="handleClose"
          :collapse=isCollapse
        >
          <template v-for="(item, index) in menus">
            <el-submenu  :index="item.path" :key="index" v-if="!item.hidden">
              <template slot="title">
                <span :class="item.isIcon" slot="title">{{item.name}}</span>
              </template>
                <el-menu-item-group v-for="(child,index) in item.children" :key="index" v-show="!child.hidden">
                    <el-menu-item :class="child.isIcon" :index='child.path'>{{child.name}}</el-menu-item>
                </el-menu-item-group>
            </el-submenu>
          </template>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          教务管理系统
          <router-link to="/login">
            <el-button type="danger" style="float:right;margin-top:10px;">退出</el-button>
          </router-link>
        </el-header>
        <el-main>
          <el-card class="card">
            <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item v-for="(item,index) in this.$route.matched" :key="index">
                <strong>{{item.name}}</strong>
              </el-breadcrumb-item>
            </el-breadcrumb>
          </el-card>
            <router-view></router-view>
        </el-main>
        <el-footer>
          快樂生活，快樂工作
        </el-footer>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      isCollapse: false,
      menus: [],
      activePath: '',
    };
  },
  created() {
    this.menus = [...this.$router.options.routes];
    console.log(this.$router);
    this.activePath = this.menus[2].children[2].path
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>
<style lang="scss">
.home {
  .el-header,
  .el-footer {
    background-color: #b3c0d1;
    color: #333;
    text-align: center;
    line-height: 60px;
    height: 100%;
  }
  .el-footer{
    position:relative;
    .delBtn{
      position:absolute;
      right:10px;
      bottom:10px;
    }
    .breadcrumb{
      float:left;
      a{
        text-decoration:none;
        color:black;
      }
      a:hover{
        color:#409EFF;
        transition:.3s;
      }
      span{
        margin:0 20px;
      }
    }
  }

  .el-aside {
    height:100vh;
    background-color: #d3dce6;
    color: #333;
    text-align: center;
    font-size: 14px;
  }

  .el-main {
    background-color: #e9eef3;
    color: #333;
    text-align: center;
    line-height: 160px;
     .card{
       margin-bottom: 10px;
     }
  }

  body > .el-container {
    margin-bottom: 40px;
  }
}
</style>